import json

from flask import Flask, render_template, request

app = Flask(__name__)

print(" * Loading universities data...")

# 模拟大学数据
universities = [
    {"name": "大学1", "score_range": [600, 650], "image_url": "https://via.placeholder.com/100", "description": "大学1简介", "majors": "专业1, 专业2"},
    {"name": "大学2", "score_range": [550, 599], "image_url": "https://via.placeholder.com/100", "description": "大学2简介", "majors": "专业3, 专业4"},
    {"name": "大学3", "score_range": [500, 549], "image_url": "https://via.placeholder.com/100", "description": "大学3简介", "majors": "专业5, 专业6"},
    {"name": "大学4", "score_range": [450, 499], "image_url": "https://via.placeholder.com/100", "description": "大学4简介", "majors": "专业7, 专业8"},
]

@app.route('/')
def home():
    return render_template('index.html')

@app.route('/predict', methods=['POST'])
def predict():
    score = int(request.form['score'])
    matched_universities = [uni for uni in universities if uni["score_range"][0] <= score <= uni["score_range"][1]]
    return render_template('result.html', score=score, universities=matched_universities)

@app.route('/details', methods=['POST'])
def details():
    universities = json.loads(request.form['universities'])
    return render_template('details.html', universities=universities)

if __name__ == '__main__':
    app.run(debug=True)
